import React from 'react';
import s from './index.module.less';
import ChatListItem from '../../components/ChatListItem';


class MessageList extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            totalMsgCount: 0,
            chatList: []
        }
    }

    componentDidMount() {
        const { ipcRenderer } = window.electron;
        // 订阅对于主线程的事件监听
        ipcRenderer.on('on-set-new-message', (event, data) => {
            this.setState(data)
        });

    }

    viewDetail = (...params) => {
        const { ipcRenderer } = window.electron;
        ipcRenderer.send('set-goPage', { index: 0, data: { chatgroupid: params[1].groupid }, isChild: true });
    }

    onClose = () => {
        const { ipcRenderer } = window.electron;
        ipcRenderer.send('on-ignore-all');

    }

    render() {
        const { totalMsgCount, chatList } = this.state;
        return (
            <div className={s.contain}>
                <h3>新消息({totalMsgCount})</h3>
                <div className={s.conetnt}>
                    {
                        chatList.map((v, i) => (
                            <ChatListItem
                                key={`chatItem${i}`}
                                data={v}
                                onClick={this.viewDetail}
                            />
                        ))
                    }
                </div>
                <div className={s.footer}>
                    <span onClick={this.onClose}>忽略全部</span>
                </div>
            </div>
        )
    }
}

export default MessageList